<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加收件人信息</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
		<script type="text/javascript" src="/webapp/js/common/cities.js"></script>

	</head>
	<body>

		<div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div class="nav" id="nav"></div>
                <div class="easyui-panel" style="border:none;">
                	<form id="ff" name="ff">
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >企业名称：</label>
                            <input type="text" class="easyui-textbox" name="company" style="width:200px;"  data-options="required:true" />
                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >负责人姓名：</label>
                            <input type="text" class="easyui-textbox" name="principal" style="width:200px;"  data-options="required:true" />
                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >职务：</label>
                            <input type="text" class="easyui-textbox" name="position" style="width:200px;" />
                        </div>

                        <div style="margin-bottom:20px;">
                            <label class="item-label" ><span class="item-required">*</span>邮件地址：</label>
                            <input type="text"id="email" class="easyui-textbox" name="emailAddress" style="width:200px;"prompt="请输入正确邮箱地址" data-options="required:true" />

                        </div>
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >备注：</label>
                            <input type="text" class="easyui-textbox" name="remarks" style="width:200px;" />
                        </div>
                        <div style="margin-bottom:20px;margin-left:100px;">
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px" onclick="submitForm()">保存</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" style="width:80px;" onclick="clearForm()">取消</a>
                        </div>
                	</form>
                </div>
            </div>
		</div>
	</body>

    <script type="text/javascript">

        var id = getQueryParameter("id");
        $(function(){
            setNav();
            initFormData();


        });
        function initFormData(){
            if(id){
                $.ajax({
                    url:config.url+"/recipientUser/"+id,
                    type:"GET",
                    dataType:"json",
                    data:JSON.stringify(id),
                    contentType:"application/json;charset=UTF-8",
                    xhrFields:{withCredentials:true},
                    success:function(data){
                        //填充表单
                        if(data){
                            $("#ff").form("load",changeProperty2String(data));
                        }
                    },
                    error:function(){

                    }
                });

            }

        }
        function submitForm(){
            var email=$("#email").textbox('getValue');
            if(email=="") {
                alert("电子邮件不能为空");
                return false;
            } else {
               var reg=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
                if(!reg.test(email)) {
                    alert("非法的电子邮件");
                    return false;
                }
            }

            $("#ff").form("submit",{
               onSubmit:function(){
                  var valid = $(this).form('enableValidation').form('validate');
                  if(valid){
                      var mall = getFormData(document.getElementById("ff"));
                      var method = "POST";
                        if(id){
                          method = "PATCH";
                          mall.id = id;
                        }
                      $.ajax({
                         url:config.url+"/recipientUser",
                         type:method,
                         data:JSON.stringify(mall),
                         dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         beforeSend:function(){
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"操作进行中..."
							});
                         },
                         complete:function(){
                            $.messager.progress("close");
                         },
                         xhrFields:{withCredentials:true},
                          success:function(data){
                              $.messager.alert("提示","操作成功","info",function(){
                                  window.parent.closeCurrentTab(true);
                              });
                          },
                          error:function(XMLHttpRequest,textStatus,thrown){
                              $.messager.alert("提示","操作失败","error");
                          }
                      });
                       return false;
                    }
                    return false;

               }
          });
        }
        function clearForm(){
            window.parent.closeCurrentTab();
        }

    </script>
</html>